package P206;

import java.util.List;

/**
 * @Author DJ同学
 * @Date 2021/2/11 12:24
 * @Version 1.0
 * @Name 反转链表
 * @Problem https://leetcode-cn.com/problems/reverse-linked-list/
 * @Idea 画图比较好理解 需要三个指针
 */
public class Solution {
    public ListNode reverseList(ListNode head) {
        if(head==null) return null;
        ListNode pre=null;
        ListNode next;
        while(head!=null){
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }
}
